<?php

class Condicoes_Vendas_M extends I_Model {

    protected $_table_name = 'condicoes_pagamentos';
    protected $_primary_key = 'ID';
    protected $_primary_filter = 'intval';
    protected $_order_by = 'ID';
    public $rules = array();
    protected $_timestamps = FALSE;

    public function __construct() {
        parent::__construct();
    }
    
    
    
    function by_leilao($id){
    	
    	
    	$this->db->select('le.ID AS COD_LEILAO, cm.*, pg.*')
    	->from('leiloes as le')
    	->join('comitentes as cm', 'cm.ID=le.COMITENTE_ID')
    	->join('condicoes_pagamentos as pg', 'pg.ID=le.CONDICAO_VENDA_ID')
    	->where(array('le.ID' => $id));
    	  return $this->db->get()->row();
    	 
    }
    
    
    function habilitacao($id){
    	$this->db->select("cm.*,le.*,(GROUP_CONCAT(lt.NUM_LOTE)) as LOTES,pg.CONDICAO_PAGAMENTO")
    	         ->from('leiloes as le')
    	          ->join('lotes as lt','lt.LEILAO_ID=le.ID')
    	          ->join('comitentes as cm', 'cm.ID=le.COMITENTE_ID')
    	          ->join('condicoes_pagamentos as pg', 'pg.ID=le.CONDICAO_VENDA_ID')
    	          ->where('le.ID',$id)
                  ->group_by('le.ID') ;

    	$q = $this->db->get();
        if($q->num_rows() == 0){
            return false;
        }
    	$r = $q->row();
    	return $r;
    	//echo '<pre>';
    	//print_r($r);
    }
    

}
